#include <mips/regdef.h>
#include <sys/syscall.h>

	.text
	.align 	2
	.global length
	.ent 	length

length:
	.frame	$fp,40,ra
	.set noreorder
	.cpload	t9
	.set reorder
	subu	sp,sp,40

	# Guardo los registros
	.cprestore 24
	sw	ra,32(sp)
	sw	$fp,28(sp)
	move	$fp,sp

	# Guardo el puntero
	sw	a0	,40($fp)  	// str
	sw	zero, 20($fp)	// i
	sw	zero, 16($fp)	// c
	
	lw	t0	,	40($fp)
	li	v0, 0
	
while_loop:
	lb	t1	,	0(t0)
	beqz	t1, length_return
	addiu	t0, t0, 1	// i++
	addiu	v0, v0, 1
	j 	while_loop
	
length_return:
	# destruyo el stack
	move	sp, $fp
	lw	$fp, 28(sp)
	lw	ra,  32(sp)
	addu	sp, sp, 40

	j	ra
	.end	length
